<style type="text/css">
#table-2 {
	border: 1px solid #e3e3e3;
	background-color: #f2f2f2;
        width: 100%;
	border-radius: 6px;
	-webkit-border-radius: 6px;
	-moz-border-radius: 6px;
}
#table-2 td, #table-2 th {
	padding: 5px;
	color: #333;
}
#table-2 thead {
	font-family: "Lucida Sans Unicode", "Lucida Grande", sans-serif;
	padding: .2em 0 .2em .5em;
	text-align: left;
	color: #4B4B4B;
	background-color: #C8C8C8;
	background-image: -webkit-gradient(linear, left top, left bottom, from(#f2f2f2), to(#e3e3e3), color-stop(.6,#B3B3B3));
	background-image: -moz-linear-gradient(top, #D6D6D6, #B0B0B0, #B3B3B3 90%);
	border-bottom: solid 1px #999;
}
#table-2 th {
	font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
	font-size: 14px;
	line-height: 20px;
	font-style: normal;
	font-weight: normal;
	text-align: center;
	text-shadow: white 1px 1px 1px;
}
#table-2 td {
	line-height: 20px;
	font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
	font-size: 10px;
	
	border-bottom: 1px solid #fff;
	border-right: 1px solid #fff;
	border-top: 1px solid #fff;
}
#table-2 td:hover {
	background-color: #fff;
}
</style>
<?php
    $modules=$this->db->get("tbl_user_modules")->result_array();
?>
<div class="easyui-layout" fit="true">
<div region="center" border="false" style="overflow:auto;padding:5px;background:#fff;border:1px solid #ccc;height:<?=$tinggiregion?>px;">
<a id="btnCK_policy" class="l-btn l-btn-plain" iconcls="check_all" href="#" onclick="$('input:checkbox').attr('checked','checked')">
    <span class="l-btn-left">
        <span class="l-btn-text check_all" style="padding-left: 20px;">Check All</span>
    </span>
</a>
<a id="btnCK_policy" class="l-btn l-btn-plain" iconcls="uncheck_all" href="#" onclick="$('input:checkbox').removeAttr('checked')">
    <span class="l-btn-left">
        <span class="l-btn-text uncheck_all" style="padding-left: 20px;">UnCheck All</span>
    </span>
</a>
<br/>
<table id='table-2'>
    <thead>
        
            <?php 
            $module_title="";
            $function_title="";
            $is_create="";
            $is_update="";
            $is_read="";
            $is_delete="";
            foreach ($modules as $key => $value) { ?>
                
                <?php 
                    $sql = "SELECT * FROM tbl_user_module_functions WHERE tbl_module_id='".$value['id']."'";
                    $functions = $this->db->query($sql)->result_array();
                    $colspan = $this->db->query($sql)->num_rows();
                    foreach ($functions as $keys => $values) {
                        $function_title.="<td>".$values['function_name']."</td>";
                        $sql2="SELECT * FROM tbl_user_policy WHERE idx_role_id='$id' AND tbl_module_id='".$value['id']."' AND tbl_function_id='".$values['id']."'";
                        $crud = $this->db->query($sql2)->result_array();
                        $crud_count = count($crud);
                        $create_checked="";
                        $read_checked="";
                        $update_checked="";
                        $delete_checked="";
                        if($crud_count >0){
                            foreach ($crud as $k => $v) {
                               if($values["id"]==$v["tbl_function_id"]){
                                   $create_checked= ($v["is_create"]==1)?"checked":"";
                                   $read_checked = ($v["is_read"]==1)?"checked":"";
                                   $update_checked = ($v["is_update"]==1)?"checked":"";
                                   $delete_checked = ($v["is_delete"]==1)?"checked":"";                                           
                               }
                            }
                        }
                        $is_create.="<td><center><input class='ck' data='C_r_".$id."_m_".$value['id']."_f_".$values['id']."' type='checkbox' name='check_create[]' $create_checked/></center></td>";
                        $is_update.="<td><center><input class='ck' data='U_r_".$id."_m_".$value['id']."_f_".$values['id']."' type='checkbox' name='check_update[]' $update_checked/></center></td>";
                        $is_read.="<td><center><input class='ck' data='R_r_".$id."_m_".$value['id']."_f_".$values['id']."' type='checkbox' name='check_read[]' $read_checked/></center></td>";
                        $is_delete.="<td><center><input class='ck' data='D_r_".$id."_m_".$value['id']."_f_".$values['id']."' type='checkbox' name='check_delete[]' $delete_checked/></center></td>";
                    }
                    $module_title .= "<th colspan='$colspan'>".$value['module_name']."</th>";
                ?>
                
            <?php } ?>
        <tr>
            <th>Module Name</th><?=$module_title?>            
        </tr>
        <tr>
            <td>Functions Name</td><?=$function_title?>
        </tr>
        
    </thead> 
    <tbody>
        <tr>
            <td>Create</td><?=$is_create?>
        </tr>
        <tr>
            <td>Read</td><?=$is_read?>
        </tr>
        <tr>
            <td>Update</td><?=$is_update?>
        </tr>
        <tr>
            <td>Delete</td><?=$is_delete?>
        </tr>
    </tbody>
</table>
<div region="south" border="false" style="margin-top:15px 0;">
    <br/>
    <a id="btnSend_policy" data="<?=$id?>" class="l-btn l-btn-plain" iconcls="disk" href="#">
    <span class="l-btn-left">
        <span class="l-btn-text disk" style="padding-left: 20px;">Simpan</span>
    </span>
    </a>
    <a id="btnBatal_policy" class="l-btn l-btn-plain" onclick="kembali('user_role')" iconcls="cancel" href="#">
        <span class="l-btn-left">
            <span class="l-btn-text cancel" style="padding-left: 20px;">Batal</span>
        </span>
    </a>
</div>
</div>
</div>
<script type="text/javascript" src="<?=base_url()?>assets/js/setup/policy.js"></script>